package com.ruoyi.message.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.message.domain.IotBroadcastMessage;
import com.ruoyi.message.service.IIotBroadcastMessageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 广播消息通知Controller
 * 
 * @author wujiale
 * @date 2025-04-26
 */
@RestController
@RequestMapping("/broadcast/broadcast")
public class IotBroadcastMessageController extends BaseController
{
    @Autowired
    private IIotBroadcastMessageService iotBroadcastMessageService;

    /**
     * 查询广播消息通知列表
     */
//    @PreAuthorize("@ss.hasPermi('broadcast:broadcast:list')")
    @GetMapping("/list")
    public TableDataInfo list(IotBroadcastMessage iotBroadcastMessage)
    {
        startPage();
        List<IotBroadcastMessage> list = iotBroadcastMessageService.selectIotBroadcastMessageList(iotBroadcastMessage);
        return getDataTable(list);
    }

    /**
     * 导出广播消息通知列表
     */
    @PreAuthorize("@ss.hasPermi('broadcast:broadcast:export')")
    @Log(title = "广播消息通知", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IotBroadcastMessage iotBroadcastMessage)
    {
        List<IotBroadcastMessage> list = iotBroadcastMessageService.selectIotBroadcastMessageList(iotBroadcastMessage);
        ExcelUtil<IotBroadcastMessage> util = new ExcelUtil<IotBroadcastMessage>(IotBroadcastMessage.class);
        util.exportExcel(response, list, "广播消息通知数据");
    }

    /**
     * 获取广播消息通知详细信息
     */
    @PreAuthorize("@ss.hasPermi('broadcast:broadcast:query')")
    @GetMapping(value = "/{messageId}")
    public AjaxResult getInfo(@PathVariable("messageId") Long messageId)
    {
        return success(iotBroadcastMessageService.selectIotBroadcastMessageByMessageId(messageId));
    }

    /**
     * 新增广播消息通知
     */
    @PreAuthorize("@ss.hasPermi('broadcast:broadcast:add')")
    @Log(title = "广播消息通知", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IotBroadcastMessage iotBroadcastMessage)
    {
        return toAjax(iotBroadcastMessageService.insertIotBroadcastMessage(iotBroadcastMessage));
    }

    /**
     * 修改广播消息通知
     */
    @PreAuthorize("@ss.hasPermi('broadcast:broadcast:edit')")
    @Log(title = "广播消息通知", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IotBroadcastMessage iotBroadcastMessage)
    {
        return toAjax(iotBroadcastMessageService.updateIotBroadcastMessage(iotBroadcastMessage));
    }

    /**
     * 删除广播消息通知
     */
    @PreAuthorize("@ss.hasPermi('broadcast:broadcast:remove')")
    @Log(title = "广播消息通知", businessType = BusinessType.DELETE)
	@DeleteMapping("/{messageIds}")
    public AjaxResult remove(@PathVariable Long[] messageIds)
    {
        return toAjax(iotBroadcastMessageService.deleteIotBroadcastMessageByMessageIds(messageIds));
    }
}
